import GameConfig from "./GameConfig";
import ZYBeanLauncher from "./zhiyun/common/abstract/ZYBeanLauncher";
import { UIMgr } from "./zhiyun/common/manager/viewMgr";
import { ZYNetMgr } from "./zhiyun/common/server/ZYNetMgr";
import ErrorUtils from "./zhiyun/common/util/ErrorUtils";
import LayaUtils from "./zhiyun/common/util/LayaUtils";
import adModel from "./zhiyun/main/view/adView/adModel";

/**
 * 
 * @author: xj.huang
 * @date: 2021/07/30 16:41:56
 */
class ZYSDKClazz {
    /**配置 */
    private _config: ZYSDK.IZYSDKConfigVo;
    /**是否激活 */
    private _hasDeployed = false;
    private _beanLauncher: ZYBeanLauncher;
    private _gameConfig: any;
    constructor() {
        Laya.Browser.window;
    }
    private set configurate($config: ZYSDK.IZYSDKConfigVo) {
        this._config = $config;

    }
    private get configurate() {
        return this._config
    }
    /**
     * 运行激活入口
     * @param config 
     */
    public async initRun(config) {
        this.configurate = config;
        ZYNetMgr.API = this.config.server.API_HOST;
        ZYNetMgr.DATA = this.config.server.DATA_HOST;
        Laya.SoundManager.autoStopMusic = false
        if (!this.configurate) {
            ErrorUtils.throwNormalError("请先执行 YLSDK.configurate 进行配置！");
        } else {
            UIMgr.Init()
            this.hasDeployed = true;
            GameConfig.physicsDebug = false;//无效的操作，目的只是为了import一下sdk中的GameConfig，进行init调用，做部分ui中的类映射
            this.gameConfig = (await LayaUtils.asyncLoadJson(this.config.gameConfig))[0]
            await UIMgr.asyncOpen(ViewRes.VIEW_LOAD) as ZYSDK.loading;
            console.log("--------->>>>>>>")
            this._beanLauncher = new ZYBeanLauncher();
            this._beanLauncher.run();
        }
    }
    /**游戏入口配置 */
    get config() {
        return this._config
    }
    /**
     * 游戏数据配置
     */
    public get gameConfig(): Game.Config {
        return this._gameConfig;
    }
    public set gameConfig($value) {
        this._gameConfig = $value;
        adModel.gameConfig = this.gameConfig;
        UIMgr.gameConfig = this.gameConfig
    }
    /**
     * 获取误点总开关:
     * - true - 开启 
     * - false - 关闭
     * @returns true \ false
     */
    public get getLateOff(){
        // if(adModel.gridShowType||adModel.bannerShowType){
            if(this.gameConfig.ad_move_conf.is_show===1){
                return true
            }else{
                return false;
            }
        // }
        // return false;
    }
    /**
     * 是否启动
     * @emits "hasDeployed" (赋值成功后会派发事件，并带上IEventPayload作为参数)
     */
    public get hasDeployed():boolean  {
        return this._hasDeployed;
    }
    
    public set hasDeployed($value:boolean ) {
        this._hasDeployed = $value
    }
}

export const ZYSDK = new ZYSDKClazz()